package sg.edu.nus.iss.vmcs.customer;

import java.awt.*;
import java.awt.event.ActionListener;
import sg.edu.nus.iss.vmcs.store.DrinksBrand;
import sg.edu.nus.iss.vmcs.store.StoreItem;

    /**
     * This class represents the boundary object that enables a drink to be
     * displayed and selected. It also displays the stock availability of the drink.
     * 
    */
public class DrinkSelectionItem extends Panel {

    /**
     * Active Color
     */
    public final static Color ACT_COLOR = Color.white;
    /**
     * In Stock state color
     */
    public final static Color IN_STK = Color.GRAY;
    /**
     * Out of Stock state color
     */
    public final static Color OUT_STK = Color.RED;
    private Button drinkName;
    private TextField drinkPrice;
    private TextField drinkStatus;

    /**
     * This constructor creates an instance of the Drink Selection Item.
     */
    public DrinkSelectionItem(StoreItem item) {
        DrinksBrand db = (DrinksBrand) item.getContent();

        drinkName = new Button();
        drinkName.setFont(new Font("Helvetica", Font.BOLD, 14));
        drinkName.setBackground(ACT_COLOR);

        drinkPrice = new TextField("     ");
        drinkPrice.setEditable(false);

        drinkStatus = new TextField("Not in Stock");
        drinkStatus.setEditable(false);

        this.setLayout(new GridLayout(1, 3));
        Panel tp = new Panel(new GridLayout(0, 1));
        tp.add(drinkName);
        Panel tp1 = new Panel();
        tp1.add(drinkPrice);
        Panel tp2 = new Panel();
        tp2.add(drinkStatus);
        this.add(tp);
        this.add(tp1);
        this.add(tp2);
    }

    /**
     * This operation activates or deactivates the drink selection item button.
     * This operation also displays OUT OF STOCK messages where appropriate.
     *
     * @param active boolean state setting the status True / False
     */
    public void setItemState(boolean active) {
        drinkName.setEnabled(active);
        drinkStatus.setEnabled(!active);
    }

    /**
     * This operation sets the status of the Drinks selection Item.
     *
     * @param active boolean state set as Active / Deactive
     */
    public void setItemActive(boolean active) {
        drinkName.setEnabled(active);
        drinkStatus.setEnabled(active);
    }

    /**
     * This operation sets the name on the Drink Selection Item.
     */
    public void setName(String name) {
        drinkName.setLabel(name);
    }

    /**
     * This operation sets the price on the Drink Selection Item
     *
     * @param price Price for drinks brand
     */
    public void setPrice(int price) {
        String wStr = String.valueOf(price) + " c";
        drinkPrice.setText(wStr);
    }

    /**
     * This operation attaches a listener to the Button object.
     *
     * @param l ActionListener
     */
    public void addListener(ActionListener l) {
        drinkName.addActionListener(l);
    }

    /**
     * This operation sets the action command to the Button object.
     *
     * @param cmd String parameter
     */
    public void setActionCommand(String cmd) {
        drinkName.setActionCommand(cmd);
    }
}
